#ifndef __Violet_Time_H__
#define __Violet_Time_H__

#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <chrono>

namespace violet::time {

struct Time {
    friend class boost::serialization::access;

    int64_t sec{0};
    int32_t msec{0};

    Time() = default;
    Time(int64_t _sec, int32_t _msec) : sec(_sec), msec(_msec) {}

    template <class _Archive>
    void serialize(_Archive& arch, const uint32_t /* file_version */) {
        arch & sec & msec;
    }
    static auto Now() -> Time;
};

#ifndef __Time_Now_Time_Static_Decl__
auto Time::Now() -> Time {
    auto now      = std::chrono::system_clock::now();
    auto duration = now.time_since_epoch();
    auto sec      = std::chrono::duration_cast<std::chrono::seconds>(duration).count();
    auto msec = static_cast<int32_t>(std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() % 1000);
    return Time{sec, msec};
}
#define __Time_Now_Time_Static_Decl__
#endif // __Time_Now_Time_Static_Decl__

} // namespace violet::time


#endif // __Violet_Time_H__